package domain;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import domain.util.TypesResource;

/**
 * General attributes.
 * 
 * @author Diogo Anderson
 * @author Felipe Sampaio
 * @author Vinicius Cavalcanti
 */

@Entity
@Table(name="RESOURCE")
public class Resource {

	private long id;
	
	private String title, creator, cutter, date, contributor, source,
			cduClassification, edition, description, country, languageName,
			publisherName, publisherPlace;
	private TypesResource type;
	
	private String issn, isbn, volumeNumber, serialNumber, degree, marcCode, number;


	private Set<Unit> units;
	
	private Set<Keyword> keywords;
	
	@Id
	@Column(name = "RESOURCE_ID")
	@GeneratedValue
	public long getId() {
		return id;
	}
	
	public void setId(long id) {
		this.id = id;
	}


	@Column(name = "TITLE", nullable=false, length=100)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "CREATOR", nullable=false, length=100)
	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@Column(name = "CUTTER", length=100)
	public String getCutter() {
		return cutter;
	}

	public void setCutter(String cutter) {
		this.cutter = cutter;
	}

	@Column(name = "PUBLISHER_DATE", length=10)
	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	@Column(name = "CONTRIBUTOR", length=100)
	public String getContributor() {
		return contributor;
	}

	public void setContributor(String contributor) {
		this.contributor = contributor;
	}

	@Column(name = "SOURCE", length=100)
	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	@Column(name = "CDU", length=100)
	public String getCduClassification() {
		return cduClassification;
	}

	public void setCduClassification(String cduClassification) {
		this.cduClassification = cduClassification;
	}

	@Column(name = "DESCRIPTION", length=200)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "COUNTRY", length=30)
	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	@Column(name = "LANGUAGE_NAME", length=30)
	public String getLanguageName() {
		return languageName;
	}

	public void setLanguageName(String languageName) {
		this.languageName = languageName;
	}

	@Column(name = "PUBLISHER_NAME", length=100)
	public String getPublisherName() {
		return publisherName;
	}

	public void setPublisherName(String publisherName) {
		this.publisherName = publisherName;
	}

	@Column(name = "PUBLISHER_PLACE", length=100)
	public String getPublisherPlace() {
		return publisherPlace;
	}

	public void setPublisherPlace(String publisherPlace) {
		this.publisherPlace = publisherPlace;
	}
	
	
	@Column(name = "NUMBER", length=20)
	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}
	@Column(name = "ISSN", length=20)
	public String getIssn() {
		return issn;
	}

	public void setIssn(String issn) {
		this.issn = issn;
	}
	@Column(name = "ISBN", length=20)
	public String getIsbn() {
		return isbn;
	}

	public void setIsbn(String isbn) {
		this.isbn = isbn;
	}

	@Column(name = "VOLUME_NUMBER", length=50)
	public String getVolumeNumber() {
		return volumeNumber;
	}

	public void setVolumeNumber(String volumeNumber) {
		this.volumeNumber = volumeNumber;
	}
	@Column(name = "SERIAL_NUMBER", length=50)
	public String getSerialNumber() {
		return serialNumber;
	}

	public void setSerialNumber(String serialNumber) {
		this.serialNumber = serialNumber;
	}

	@Column(name = "MARC_CODE", length=100000)
	public String getMarcCode() {
		return marcCode;
	}

	public void setMarcCode(String marcCode) {
		this.marcCode = marcCode;
	}

	@OneToMany(targetEntity=Unit.class, cascade=CascadeType.ALL, mappedBy="resource")
    public Set<Unit> getUnits() { return units; }

	public void setUnits(Set<Unit> units) {
		this.units = units;
	}

	@Column(name = "TYPE", length=20)
	public TypesResource getType() {
		return type;
	}

	public void setType(TypesResource type) {
		this.type = type;
	}

	@ManyToMany
    @JoinTable(name="RESOURCE_KEYWORDS")
	public Set<Keyword> getKeywords() {
		return keywords;
	}

	public void setKeywords(Set<Keyword> keywords) {
		this.keywords = keywords;
	}

	@Column(name = "EDITION", length=20)
	public String getEdition() {
		return edition;
	}

	public void setEdition(String edition) {
		this.edition = edition;
	}

	@Column(name = "DEGREE", length=20)
	public String getDegree() {
		return degree;
	}

	public void setDegree(String degree) {
		this.degree = degree;
	}
	
//	private String link;
	@Column(name = "LINK", length=200)
	public String getLink()
	{
		return "<a href=\"details.jsp?id=" + getId()
			+ "&action=view\">View</a> | "
			+ "<a href=\"details.jsp?id=" + getId()
			+ "&action=edit\">Edit</a> | "
			+ "<a href=\"details.jsp?id=" + getId()
			+ "&action=delete\">Delete</a>";
	}
	public void setLink(String link)
	{

	//	this.link = link;
	}
	
	
}
